#网络ip存活
# import asyncio,pythonping
# from multiprocessing import Pool,Lock
# from IPy import IP
# # 定义ip网段
# ip = IP("192.168.1.0/24")
# def func1(x):
#     with lock:
#         # result=pythonping.ping(x, verbose=True)
#         result = pythonping.ping(x)
#         if 'Reply' in str(result):
#             print(x+"可达")
#         else:
#             print(x+"不可达")
# lock=Lock()
# if __name__ == "__main__":
#     p=Pool(processes=10,maxtasksperchild=5)
#     for x in ip:
#         p.apply_async(func=func1,args=(str(x),))
#         # tasks = [
#         #     asyncio.ensure_future(func1(str(x)))
#         # ]
#
#     # loop = asyncio.get_event_loop()
#     # loop.run_until_complete(asyncio.wait(tasks))
#     #关闭进程池，只是不接收任务
#     p.close()
#     #等待子进程执行完毕，父进程再执行
#     p.join()
#     print("end.......")

import pythonping
from multiprocessing import Process,Lock
from IPy import IP
# 定义ip网段
ip = IP("192.168.1.0/24")
def func1(x):
    with lock:
        # result=pythonping.ping(x, verbose=True)
        result = pythonping.ping(x)
        if 'Reply' in str(result):
            print(x+"可达")
        else:
            print(x+"不可达")
lock=Lock()
if __name__ == "__main__":
    p_lst = []
    for x in ip:
        p=Process(target=func1,args=(x,))
        p_lst.append(p)
        p.start()
    for p in p_lst:
        p.join()
    print("main end .....")



#爬取图片
import requests
import re
html  = "https://www.sanchuangedu.cn/"
result = requests.get(html).text
url=re.findall(r"(?<=<img src=).*(?= width=)",result,re.M)
print(url)
for i in url:
    with open(f"{i}.png", 'wb') as f:
        path=html+i
        photo=requests.get(path)
        f.write(photo.content)